package com.dhsc.service.impl.jyjk.zxyc;

import com.dhsc.domain.jkzx.zxjh.Sgwhkh;
import com.dhsc.domain.jkzx.zxjh.Zdgzkh;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.service.jyjk.zxyc.IGzaccountService;
import com.dhsc.util.CommonUtil;
import com.dhsc.view.dao.jyjk.zxyc.IGzaccountDao;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GzaccountServiceImpl
 * @description: 重点关注账户
 * @author: gx
 * @create: 2024-08-13 10:06:22
 **/
@Service
@Slf4j
public class GzaccountServiceImpl implements IGzaccountService {

    @Autowired
    private IGzaccountDao gzaccountDao;

    @Override
    public LayuiTableVo queryZdgzkhInfo(Zdgzkh zdgzkh) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            PageMethod.startPage(zdgzkh.getPage(), zdgzkh.getLimit());
            List<Zdgzkh> list = gzaccountDao.queryZdgzkhInfo(zdgzkh);
            PageInfo<Zdgzkh> pageInfo = new PageInfo<>(list);
            obj.setCount(pageInfo.getTotal());
            obj.setData(list);
            obj.setMsg("");
            obj.setCode(0);
        }catch(Exception e){
            log.error("查询重点关注账户信息出错", e);
            throw new MyException("查询重点关注账户信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryZdgzkhByZhlx() {
        ResponseObject obj = new ResponseObject();
        try{
            List<Zdgzkh> list = gzaccountDao.queryZdgzkhByZhlx();
            obj.setData(list);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("查询账户类型信息出错", e);
            throw new MyException("查询账户类型信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryZdgzkhByYyb() {
        ResponseObject obj = new ResponseObject();
        try{
            List<Zdgzkh> list = gzaccountDao.queryZdgzkhByYyb();
            obj.setData(list);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("查询营业部信息出错", e);
            throw new MyException("查询营业部信息出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo querySgwhkhInfo(Sgwhkh sgwhkh) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            PageMethod.startPage(sgwhkh.getPage(), sgwhkh.getLimit());
            if (CommonUtil.isNotEmptyObj(sgwhkh.getZjlb())&&CommonUtil.isNotEmptyObj(sgwhkh.getKhh())){
                List<Sgwhkh> list = gzaccountDao.querySgwhkhInfo(sgwhkh);
                PageInfo<Sgwhkh> pageInfo = new PageInfo<>(list);
                obj.setCount(pageInfo.getTotal());
                obj.setData(list);
            }else{
                obj.setCount(0);
                obj.setData(null);
            }
            obj.setMsg("");
            obj.setCode(0);
        }catch(Exception e){
            log.error("查询重点关注账户手工维护信息出错", e);
            throw new MyException("查询重点关注账户手工维护信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject setSgwhkhInfo(Sgwhkh sgwhkh) {
        ResponseObject obj = new ResponseObject();
        try{
            if ("1".equals(sgwhkh.getStatus())){
                gzaccountDao.insertSgwhkhInfo(sgwhkh);
            }else{
                gzaccountDao.updateSgwhkhInfo(sgwhkh);
            }
            obj.setStatus(200);
        }catch(Exception e){
            log.error("保存重点关注账户手工维护信息出错", e);
            throw new MyException("保存重点关注账户手工维护信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveGzaccount(Zdgzkh zdgzkh) {
        ResponseObject obj = new ResponseObject();
        try{
//            gzaccountDao.insertZdgzkh(zdgzkh);
            Sgwhkh sgwhkh = new Sgwhkh();
            sgwhkh.setKhh(zdgzkh.getKhh());
            sgwhkh.setKhlx(zdgzkh.getKhlx());
            sgwhkh.setQsrq(zdgzkh.getQsrq());
            sgwhkh.setJzrq(zdgzkh.getJzrq());
            sgwhkh.setBz(zdgzkh.getBz());
            sgwhkh.setKhlb("");
            sgwhkh.setZjlb("");
            sgwhkh.setZjbh("");
            sgwhkh.setYmth("");
            gzaccountDao.insertSgwhkhInfo(sgwhkh);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("保存重点关注账户手工维护信息出错", e);
            throw new MyException("保存重点关注账户手工维护信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryKhmcByKhh(Zdgzkh zdgzkh) {
        ResponseObject obj = new ResponseObject();
        try{
            String khmc = gzaccountDao.queryKhmcByKhh(zdgzkh);
            obj.setData(khmc);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("保存重点关注账户手工维护信息出错", e);
            throw new MyException("保存重点关注账户手工维护信息出错",e);
        }
        return obj;
    }
}
